package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Document;
import com.kaishengit.service.DocumentService;
import com.kaishengit.util.web.ServletUtil;

public class DocumentEdit extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		
		String id = request.getParameter("id");
		
		Document document = new DocumentService().findById(id);
		
		request.setAttribute("document", document);
		ServletUtil.forward(request, response, "document_edit");

	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html");
		String id = request.getParameter("id");
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		
		new DocumentService().update(id,title,content);
		ServletUtil.redirect(response, "documentlist.jspx");
	}


}
